/**
 * 底层函数的声明
 * functions.h
 */

#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__ 

#include "module.h"

extern Club *head;

extern int load();
extern int save();
extern void show_all();


extern void swap_str(char *dest, const char *src);
extern char * tag_to_string(char tag);
extern char * status_to_string(char status);
// extern void swap_itoa(int num, char *str);
extern int insert_club(const char *clubname, const char *coach);
extern void insert_club_with_input();
extern int show_clubs();
extern Club * query_club(const char *data, 
				  int flag);
extern Club * query_club_by_name(const char *name);
extern Club * query_club_by_coach(const char *coach);
extern void search_club();
extern int query_club_by_substring(const char *substr);
extern int query_club_by_coach_substr(const char *substr);
extern void select_club(const char *mode);
extern void show_club(Club * const p);


extern int insert_player(const char *clubname, 
				  const char *name, 
				  const char rank);
extern void insert_player_with_input();
extern Player * query_player_by_name(const	char *clubname,
							  const char *name);
extern int query_player_by_name_only(const char *player);
extern int query_player_by_club_and_victories(const char *clubname, int victories);
extern void select_players_by_name();
extern void select_player_by_club_and_name();
extern void select_players_by_club_and_victories();
extern void show_players_by_name(const char *name);
extern void show_player_by_club_and_name(const char *clubname,
								  const char *name);
extern void show_players_by_club_victories(const char *clubname, 
									int victories);


extern void insert_game(const int id, 
				 const char tag,
				 const char *blackteam, 
				 const char *whiteteam,
				 const char *black, 
				 const char *white, 
				 const char status, 
				 Player *pp);
extern void insert_game_with_input();
extern Game * query_game(const char *clubname,
 				  int id, 
 				  const char *player);
extern int query_game_before_delete(const int id, 
							const char *blackteam,
							const char *whiteteam,
							const char *black,
							const char *white);
extern int check_game(const char *clubname, 
			   int id, 
			   const char *player, 
			   char tag);
extern void show_game(Game * pg);
extern int query_game_by_id_and_player(int id, const char *player);
extern int query_game_by_status(const char *player, int flag);
extern int get_winner(const char *player,
			   const char *black, 
			   const char *white,
			   char status);
extern int check_gamepoint(const int id, 
					const char tag,
					const char *blackteam, 
				 	const char *whiteteam,
					const char *black, 
					const char *white, 
					const char status, 
					Player *pp);
extern void analysis_gamepoint(const int id,
				 	    Player *pp);
extern int check_sitepoint(int id, 
					const char *clubname);
// extern void check_all_point();


extern void update_coach_by_clubname();
extern void update_clubname_of_player();
extern void update_rank();
extern void update_game();


extern void delete_club(const char *clubname);
extern void delete_club_with_input();
extern void delete_player(const char *clubname, 
				   const char *player);
extern void delete_player_with_input();
extern void delete_game_single(int id,
						const char *clubname,
						const char *player);
extern void delete_game(int id,
				 const char *blackteam,
				 const char *whiteteam,
				 const char *black,
				 const char *white);
extern void delete_game_with_input();

#endif
